package com.marvels.dubbo.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fintech.third.model.credit.CallCountDto;
import com.fintech.third.model.credit.CreditReportMessageDto;
import com.fintech.third.model.credit.CreditReportPortrait;
import com.fintech.third.model.credit.ZXPersonalLoanApplyInfo;
import com.fintech.third.model.credit.ZXPersonalLoanOrderInfo;
import com.fintech.third.model.credit.ZXpersonalLoanOrderDetailsInfo;
import com.fintech.third.model.moxie.dataprovide.IntMxCallDetails;
import com.github.pagehelper.PageInfo;
import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.dubbo.dto.CreditRepotOperatorDto;
import com.marvels.dubbo.service.DubboThirdCreditReportService;


@RestController
@RequestMapping("/credit/report/service")
public class DubboCreditReportController {
	
	@Autowired
	private DubboThirdCreditReportService thirdCreditReportService;
	
	@RequestMapping("getUserOperatorSummary/{loanId}")
	public MarvelsResultDTO getUserOperatorSummary(@PathVariable("loanId")String loanId){
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getUserOperatorSummary(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	/**
	 * 获取用户通话行为分析
	 * wanggang
	 * @return
	 */
	@RequestMapping("selectCallLocationPercent/{loanId}")
	public MarvelsResultDTO selectCallLocationPercent(@PathVariable("loanId")String loanId){
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.selectCallLocationPercent(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	/**
	 * 获取用户通话行为分析
	 * wanggang
	 * @return
	 */
	@RequestMapping("selectCallTypePercent/{loanId}")
	public MarvelsResultDTO selectCallTypePercent(@PathVariable("loanId")String loanId){
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.selectCallTypePercent(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	
	/**
	 * 获取用户通话行为分析
	 * wanggang
	 * @return
	 */
	@RequestMapping("getCallCount/{loanId}")
	public MarvelsResultDTO getCallCount(@PathVariable("loanId")String loanId){
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getCallCount(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	/**
	 * 获取用户通话行为分析
	 * wanggang
	 * @return
	 */
	@RequestMapping("getCallCountWithMonth/{loanId}/{month}")
	public MarvelsResultDTO getCallCountWithMonth(@PathVariable("loanId")String loanId,@PathVariable("month")String month){
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getCallCountWithMonth(loanId,month));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	
	/**
	 * 陌生号码统计
	 * wanggang
	 * @return
	 */
	@RequestMapping("getStrangerNumberStatistics/{loanId}")
	public MarvelsResultDTO getStrangerNumberStatistics(@PathVariable("loanId")String loanId){
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getStrangerNumberStatistics(loanId,"12345"));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	/**
	 *通话时间段分析
	 *	 * wanggang
	 * @return
	 */
	@RequestMapping("getCallPeriodStatistics/{loanId}")
	public MarvelsResultDTO getCallPeriodStatistics(@PathVariable("loanId")String loanId){
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getCallPeriodStatistics(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}

	/**
	 * 获取用户通话行为分析
	 * wanggang
	 * @return
	 */
	@RequestMapping("getCallPeriodStatisticsWithMonth/{loanId}/{month}")
	public MarvelsResultDTO getCallPeriodStatisticsWithMonth(@PathVariable("loanId")String loanId,@PathVariable("month")String month){
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getCallPeriodStatisticsWithMonth(loanId,month));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	/**
	 * 获取用户通话行为分析
	 * wanggang
	 * @retur
	 */
	@RequestMapping("queryCallCountList")
	public MarvelsResultDTO queryCallCountList(@RequestBody CreditRepotOperatorDto creditRepotOperatorDto){
		try {
			Map<String,Object> map = new HashMap<>();
			map.put("loanId", creditRepotOperatorDto.getLoanId());
			map.put("userId", "123");
			map.put("pageIndex", (creditRepotOperatorDto.getPageNo()-1)*creditRepotOperatorDto.getPageSize());
			map.put("pageSize", creditRepotOperatorDto.getPageSize());
			map.put("month", creditRepotOperatorDto.getMonth());
			map.put("mobile", creditRepotOperatorDto.getMobile());
			CreditReportMessageDto dto = thirdCreditReportService.queryCallCountList(map);
			PageInfo<CallCountDto> pageInfo = new PageInfo<CallCountDto>((List<CallCountDto> )dto.getData());
			pageInfo.setTotal(dto.getTotalSize());
			pageInfo.setPages(Integer.parseInt(((dto.getTotalSize()%creditRepotOperatorDto.getPageSize()==0?dto.getTotalSize()/creditRepotOperatorDto.getPageSize():
					dto.getTotalSize()/creditRepotOperatorDto.getPageSize()+1)+"")));
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),pageInfo);
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("queryCallCountListWithMonth")
	public MarvelsResultDTO queryCallCountListWithMonth(@RequestBody CreditRepotOperatorDto creditRepotOperatorDto){
		try {
			Map<String,Object> map = new HashMap<>();
			map.put("loanId", creditRepotOperatorDto.getLoanId());
			map.put("userId", "123");
			map.put("pageIndex", (creditRepotOperatorDto.getPageNo()-1)*creditRepotOperatorDto.getPageSize());
			map.put("pageSize", creditRepotOperatorDto.getPageSize());
			map.put("month", creditRepotOperatorDto.getMonth());
			map.put("mobile", creditRepotOperatorDto.getMobile());
			CreditReportMessageDto dto = thirdCreditReportService.queryCallCountListWithMonth(map);
			PageInfo<CallCountDto> pageInfo = new PageInfo<CallCountDto>((List<CallCountDto> )dto.getData());
			pageInfo.setTotal(dto.getTotalSize());
			pageInfo.setPages(Integer.parseInt(((dto.getTotalSize()%creditRepotOperatorDto.getPageSize()==0?dto.getTotalSize()/creditRepotOperatorDto.getPageSize():
					dto.getTotalSize()/creditRepotOperatorDto.getPageSize()+1)+"")));
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),pageInfo);
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("getCallDetailList")
	public MarvelsResultDTO getCallDetailList(@RequestBody CreditRepotOperatorDto creditRepotOperatorDto){
		try {
			Map<String,Object> map = new HashMap<>();
			map.put("loanId", creditRepotOperatorDto.getLoanId());
			map.put("userId", "123");
			map.put("pageIndex", (creditRepotOperatorDto.getPageNo()-1)*creditRepotOperatorDto.getPageSize());
			map.put("pageSize", creditRepotOperatorDto.getPageSize());
			map.put("month", creditRepotOperatorDto.getMonth());
			map.put("mobile", creditRepotOperatorDto.getMobile());
			CreditReportMessageDto dto = thirdCreditReportService.getCallDetailList(map);
			PageInfo<IntMxCallDetails> pageInfo = new PageInfo<IntMxCallDetails>((List<IntMxCallDetails> )dto.getData());
			pageInfo.setTotal(dto.getTotalSize());
			pageInfo.setPages(Integer.parseInt(((dto.getTotalSize()%creditRepotOperatorDto.getPageSize()==0?dto.getTotalSize()/creditRepotOperatorDto.getPageSize():
					dto.getTotalSize()/creditRepotOperatorDto.getPageSize()+1)+"")));
			
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),pageInfo);
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("getAddressBookList")
	public MarvelsResultDTO getAddressBookList(@RequestBody CreditRepotOperatorDto creditRepotOperatorDto){
		try {
			Map<String,Object> map = new HashMap<>();
			map.put("loanId", creditRepotOperatorDto.getLoanId());
			map.put("userId", "123");
			map.put("pageIndex", (creditRepotOperatorDto.getPageNo()-1)*creditRepotOperatorDto.getPageSize());
			map.put("pageSize", creditRepotOperatorDto.getPageSize());
			map.put("month", creditRepotOperatorDto.getMonth());
			map.put("mobile", creditRepotOperatorDto.getMobile());
			
			CreditReportMessageDto dto = thirdCreditReportService.getAddressBookList(map);
			PageInfo<IntMxCallDetails> pageInfo = new PageInfo<IntMxCallDetails>((List<IntMxCallDetails> )dto.getData());
			pageInfo.setTotal(dto.getTotalSize());
			pageInfo.setPages(Integer.parseInt(((dto.getTotalSize()%creditRepotOperatorDto.getPageSize()==0?dto.getTotalSize()/creditRepotOperatorDto.getPageSize():
					dto.getTotalSize()/creditRepotOperatorDto.getPageSize()+1)+"")));
			
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),pageInfo);
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("getMxAlipayUserInfo/{loanId}")
	public MarvelsResultDTO getMxAlipayUserInfo(@PathVariable("loanId")String loanId){
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getMxAlipayUserInfo(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("getMxAlipayBankList/{loanId}")
	public MarvelsResultDTO getMxAlipayBankList(@PathVariable("loanId")String loanId){
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getMxAlipayBankList(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("getMxAlipayAddressList/{loanId}")
	public MarvelsResultDTO getMxAlipayAddressList(@PathVariable("loanId")String loanId){
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getMxAlipayAddressList(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("getZXBasicInfo/{custCardNo}")
	public MarvelsResultDTO getZXBasicInfo(@PathVariable("custCardNo")String custCardNo){
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getZXBasicInfo(custCardNo));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("getMxCheckBlackInfo/{loanId}")
	public MarvelsResultDTO getMxCheckBlackInfo(@PathVariable("loanId")String loanId){
		try {
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),thirdCreditReportService.getMxCheckBlackInfo(loanId));
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	
	@RequestMapping("getZXApplyInfo")
	public MarvelsResultDTO getZXApplyInfo(@RequestBody CreditRepotOperatorDto creditRepotOperatorDto){
		try {
			Map<String,Object> map = new HashMap<>();
			map.put("loanId", creditRepotOperatorDto.getLoanId());
			map.put("pageIndex", (creditRepotOperatorDto.getPageNo()-1)*creditRepotOperatorDto.getPageSize());
			map.put("pageSize", creditRepotOperatorDto.getPageSize());
			
			
			CreditReportPortrait  creditReportPortrait  = thirdCreditReportService.getZXBasicInfo(creditRepotOperatorDto.getCustCardNo());
			map.put("reqNo", creditReportPortrait.getReqNo());
			CreditReportMessageDto dto1 = thirdCreditReportService.getZXApplyInfo(map);
			PageInfo<ZXPersonalLoanApplyInfo> pageInfo = new PageInfo<ZXPersonalLoanApplyInfo>((List<ZXPersonalLoanApplyInfo> )dto1.getData());
			pageInfo.setTotal(dto1.getTotalSize());
			pageInfo.setPages(Integer.parseInt(((dto1.getTotalSize()%creditRepotOperatorDto.getPageSize()==0?dto1.getTotalSize()/creditRepotOperatorDto.getPageSize():
				dto1.getTotalSize()/creditRepotOperatorDto.getPageSize()+1)+"")));
			
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),pageInfo);
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("getZXOrderInfo")
	public MarvelsResultDTO getZXOrderInfo(@RequestBody CreditRepotOperatorDto creditRepotOperatorDto){
		try {
			Map<String,Object> map = new HashMap<>();
			map.put("loanId", creditRepotOperatorDto.getLoanId());
			map.put("pageIndex", (creditRepotOperatorDto.getPageNo()-1)*creditRepotOperatorDto.getPageSize());
			map.put("pageSize", creditRepotOperatorDto.getPageSize());
			
			
			//LoanApplyCaseDTO dto = loanApplyCaseService.findLoanApplyCase(creditRepotOperatorDto.getLoanId());
			CreditReportPortrait  creditReportPortrait  = thirdCreditReportService.getZXBasicInfo(creditRepotOperatorDto.getCustCardNo());
			map.put("reqNo", creditReportPortrait.getReqNo());
			CreditReportMessageDto dto1 = thirdCreditReportService.getZXOrderInfo(map);
			PageInfo<ZXPersonalLoanOrderInfo> pageInfo = new PageInfo<ZXPersonalLoanOrderInfo>((List<ZXPersonalLoanOrderInfo> )dto1.getData());
			pageInfo.setTotal(dto1.getTotalSize());
			pageInfo.setPages(Integer.parseInt(((dto1.getTotalSize()%creditRepotOperatorDto.getPageSize()==0?dto1.getTotalSize()/creditRepotOperatorDto.getPageSize():
				dto1.getTotalSize()/creditRepotOperatorDto.getPageSize()+1)+"")));
			
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),pageInfo);
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("getZXOrderDetailInfo")
	public MarvelsResultDTO getZXOrderDetailInfo(@RequestBody CreditRepotOperatorDto creditRepotOperatorDto){
		try {
			Map<String,Object> map = new HashMap<>();
			map.put("loanId", creditRepotOperatorDto.getLoanId());
			map.put("pageIndex", (creditRepotOperatorDto.getPageNo()-1)*creditRepotOperatorDto.getPageSize());
			map.put("pageSize", creditRepotOperatorDto.getPageSize());
			
			
			CreditReportPortrait  creditReportPortrait  = thirdCreditReportService.getZXBasicInfo(creditRepotOperatorDto.getCustCardNo());
			map.put("reqNo", creditReportPortrait.getReqNo());
			CreditReportMessageDto dto1 = thirdCreditReportService.getZXOrderDetailInfo(map);
			PageInfo<ZXpersonalLoanOrderDetailsInfo> pageInfo = new PageInfo<ZXpersonalLoanOrderDetailsInfo>((List<ZXpersonalLoanOrderDetailsInfo> )dto1.getData());
			pageInfo.setTotal(dto1.getTotalSize());
			pageInfo.setPages(Integer.parseInt(((dto1.getTotalSize()%creditRepotOperatorDto.getPageSize()==0?dto1.getTotalSize()/creditRepotOperatorDto.getPageSize():
				dto1.getTotalSize()/creditRepotOperatorDto.getPageSize()+1)+"")));
			
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),pageInfo);
		}catch(Exception e) {
			MarvelsLogUtil.getInstance().error("获取用户运营商概要异常取",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
}
